package com.xpc.rpc.proxy.jdk;

import com.xpc.proxy.common.ObjectProxy;
import com.xpc.proxy.common.ProxyFactory;
import com.xpc.proxy.common.consumer.Consumer;

import java.lang.reflect.Proxy;

public class JdkProxy implements ProxyFactory {


    private Consumer consumer;

    private int serializationType;

    public JdkProxy(Consumer consumer,int serializationType) {
        this.consumer = consumer;
        this.serializationType = serializationType;
    }

    @Override
    public  <T> T getProxy(Class clazz) {
        ClassLoader classLoader = clazz.getClassLoader();
        Class<?>[] interfaces = new Class[]{clazz};
        return (T) Proxy.newProxyInstance(classLoader, interfaces, new ObjectProxy<T>(consumer,clazz,serializationType));
    }

}
